<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$return['buytype']=array('0'=>'普通','1'=>'多商户','2'=>'货到付款','3'=>'自提','4'=>'加星','5'=>'砍价','6'=>'拼团','7'=>'秒杀','8'=>'抽奖','9'=>'夺宝');
$return['status']=array('1'=>'待发货','2'=>'待收货','3'=>'已完成','4'=>'已关闭','5'=>'申请维权','6'=>'已维权');
$return['paytype']=array('1'=>'微信支付','2'=>'余额支付','3'=>'货到付款');
$return['ispay']=array('0'=>'未支付','1'=>'已支付');
if($_RQ['op']=='list'){
	$return['params']=array();
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid']);
    $orderby='verifydate desc';
	$total='';
	if(!empty($_RQ['ordersn'])){
		$orderid=pdo_getcolumn('jy_weishop_order',array('ordersn'=>$_RQ['ordersn']),'id');
		$verifygoodsid=pdo_getcolumn('jy_weishop_verifygoods',array('orderid'=>$orderid),'id');
		$params['verifygoodsid']=$verifygoodsid;
		$return['params']['ordersn']=$_RQ['ordersn'];
	}

	if(!empty($_RQ['storeid'])){
		$params['storeid']=intval($_RQ['storeid']);
		$return['params']['storeid']=$_RQ['storeid'];
	}
	if($_RQ['verifydate']){
		$time_range=cfc('tools')->base64_decode($_RQ['verifydate'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$return['params']['verifydate']=$time_range;
		$params['verifydate between']=array($time_range['tstart'],$time_range['tend']);
	}
	$return['list']=pdo_getslice('jy_weishop_verifygoods_log',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	foreach($return['list'] as &$v){
		$verifygoods=pdo_get('jy_weishop_verifygoods',array('id'=>$v['verifygoodsid']));
		$order=pdo_get('jy_weishop_order',array('id'=>$verifygoods['orderid']),array('mid','ordersn','buytype'));
		$v['title']=pdo_getcolumn('jy_weishop_goods',array('id'=>$verifygoods['ordergoodsid']),'title');
		$v['ordersn']=$order['ordersn'];
		$v['mid']=$order['mid'];
		$v['buytype']=$order['buytype'];
		$v['nickname']=pdo_getcolumn('core_members',array('id'=>$v['mid']),'nickname');

		if(!$v['nickname']){
			$v['nickname']='匿名用户';
		}
		$v['saler']=pdo_getcolumn('jy_weishop_store_worker',array('mid'=>$v['salerid']),'name');
		$v['store']=pdo_getcolumn('jy_weishop_store',array('id'=>$v['storeid']),'title');
	}
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'export'=>'export',
		'tabs'=>array(
			array('op'=>'list','title'=>'核销记录'),
		),
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'ordersn','title'=>'订单号','type'=>'string'),
			array('name'=>'title','title'=>'商品','type'=>'string'),
			array('name'=>'nickname','title'=>'买家','type'=>'string'),
			array('name'=>'verifynum','title'=>'核销次数','type'=>'string'),			
			array('name'=>'verifydate','title'=>'核销时间','type'=>'time'),
			array('name'=>'store','title'=>'核销门店','type'=>'string'),	
			array('name'=>'saler','title'=>'核销员','type'=>'string'),			
		),
		'action'=>array(
			array('type'=>'modal','op'=>'remark','title'=>'备注信息'),
		),),
		'search'=>array(
			array('name'=>'ordersn','width'=>15,'title'=>'订单号','type'=>'string'),
			array('type'=>'select','width'=>'15','title'=>'选择门店','name'=>'storeid','options'=>'stores','select_title'=>'请选择门店'),
			array('type'=>'time_range','width'=>'16','title'=>'核销时间','name'=>'verifydate','help'=>''),
		)
	);
	$return['htmls']=$htmls;
	$return['stores']=pdo_getall('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	exi($return);
	}
if($_RQ['op']=='export'){
	if(!empty($_RQ['ordersn'])){
		$params['ordersn']=trim($_RQ['ordersn']);
	}
	if(!empty($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
	}
	$params['uniacid']=$_SESSION['uniacid'];
	$list=pdo_getall('jy_weishop_verifygoods_log',$params);
	foreach($list as &$v){
		$verifygoods=pdo_get('jy_weishop_verifygoods',array('id'=>$v['verifygoodsid']));
		$order=pdo_get('jy_weishop_order',array('id'=>$verifygoods['orderid']),array('price','mid','ordersn','buytype','paytype','status'));
		$v['title']=pdo_getcolumn('jy_weishop_goods',array('id'=>$verifygoods['ordergoodsid']),'title');
		$v['orderstatus']=$this->order_status[$order['status']];
		$v['paytype']=$return['paytype'][$order['paytype']];
		$v['price']=$order['price'];
		$v['ordersn']=$order['ordersn'];
		$v['mid']=$order['mid'];
		$v['buytype']=$order['buytype'];
		$v['nickname']=pdo_getcolumn('core_members',array('id'=>$v['mid']),'nickname');

		if(!$v['nickname']){
			$v['nickname']='匿名用户';
		}
		$v['verifydate']=date('Y-m-d H:i:s',$v['verifydate']);
		$v['saler']=pdo_getcolumn('jy_weishop_store_worker',array('mid'=>$v['salerid']),'name');
		$v['store']=pdo_getcolumn('jy_weishop_store',array('id'=>$v['storeid']),'title');
	}
	$header=array(
		'ordersn'=>'订单号',
		'title'=>'商品',
		'nickname'=>'买家昵称',
		'price'=>'订单金额',
		'orderstatus'=>'订单状态',
		'saler'=>'核销员',
		'verifydate'=>'核销时间',
		'store'=>'核销门店',
	);
	cfc('tools')->export2excel($header,$list,'计次核销日志');
}
if($_RQ['op']=='remark'){
	$id=intval($_RQ['id']);
	$item=pdo_get('jy_weishop_verifygoods_log',array('id'=>$id),array('id','remarks'));	
	$htmls=array(
			'type'=>'look',
			'desc'=>'备注信息',
	);
	$htmls['look']=array(
			array('type'=>'text','name'=>'remarks','title'=>'备注信息'),
	);
	$return['htmls']=$htmls;
	$return['item']=$item;
	exi($return);
}
if($_RQ['op']=='del'){

	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_weishop_verifygoods_log',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_weishop_verifygoods_log',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
			}
		}
	}
	exi('删除成功！');
}
?>